nginxproxy () {
    create_network
    # nginx代理的配置文件
    cp -r ./nginxproxy ${VOLUME}
     # 生成自签证书
    openssl req -newkey rsa:2048 -nodes -keyout rsa_private.key -x509 -days 365 -out cert.crt -subj "/C=CN/ST=GD/L=SZ/O=fast/OU=dev/CN=fast.cn/emailAddress=fast@fast.cn"

    if [ -f './cert.crt' ]; then
        mv ./cert.crt ${VOLUME}/nginxproxy/conf.d
        mv ./rsa_private.key ${VOLUME}/nginxproxy/conf.d
    fi
    # 创建代理nginx服务器
    DOCKER_CMD="docker run -d --network denet --ip 10.2.2.3 \
        -p 8080:80 \
        -p 8443:443 \
        --name nginxproxy \
        -v ${VOLUME}/nginxproxy/conf.d:/etc/nginx/conf.d \
        -v ${VOLUME}/nginxproxy/nginx.conf:/etc/nginx/nginx.conf \
        -v ${VOLUME}/log/nginxproxy:/var/log/nginx \
        --restart always \
        nginx:alpine"
    docker_exec $DOCKER_CMD
}

mysql () {
    create_network
    # 创建MySQL
    DOCKER_CMD="docker run -d --network denet --ip 10.2.2.4 \
        -p 3306:3306 \
        --name mysql \
        -v ${VOLUME}/mysql:/var/lib/mysql \
        -e MYSQL_ROOT_PASSWORD=secret20 \
        --restart always \
        mysql:8"
    docker_exec $DOCKER_CMD
}

redis () {
    create_network
    # 创建Redis
    DOCKER_CMD="docker run -d --network denet --ip 10.2.2.5 \
        -p 6379:6379 \
        --name redis \
        -v ${VOLUME}/redis/data:/data \
        redis:alpine \
        redis-server --appendonly yes"
    docker_exec $DOCKER_CMD
}

mongo () {
    # 创建MongoDB
    DOCKER_CMD="docker run -d \
        -p 27017:27017 \
        --name mongo \
        -v ${VOLUME}/mongo/data/db:/data/db \
        mongo"
    docker_exec $DOCKER_CMD
}

mediawiki () {
    # 创建mediawiki
    DOCKER_CMD="docker run -d \
        -p 8017:80 \
        --name mediawiki \
        mediawiki"
    docker_exec $DOCKER_CMD
    # 创建wiki使用的MySQL
    DOCKER_CMD="docker run -d \
        -p 8018:3306 \
        --name wikimysql \
        -v ${VOLUME}/mysql_wiki:/var/lib/mysql \
        -e MYSQL_ROOT_PASSWORD=secret20 \
        mysql:5.7"
    docker_exec $DOCKER_CMD
}

phpmyadmin () {
    # 创建phpmyadmin
    DOCKER_CMD="docker run -d \
        -p 8023:80 \
        --name phpmyadmin \
        -e PMA_HOSTS=10.2.2.6,10.2.2.7 \
        -e PMA_PORTS=3306,3306 \
        -e PMA_VERBOSES=mysql,wikiMysql \
        phpmyadmin/phpmyadmin"
        # -e PMA_USER=root \
        # -e PMA_PASSWORD=secret20 \
    docker_exec $DOCKER_CMD
}

solr () {
    # solr
    DOCKER_CMD="docker run -d \
        -p 8983:8983 \
        --name solr \
        solr"
    docker_exec $DOCKER_CMD
}

httpd () {
    # apache
    DOCKER_CMD="docker run -d \
        -p 8989:80 \
        --name httpd \
        httpd:alpine"
    docker_exec $DOCKER_CMD
}

elasticsearch () {
    DOCKER_CMD="docker network create somenetwork"
    docker_exec $DOCKER_CMD
    DOCKER_CMD="docker run -d \
        --name elasticsearch \
        --net somenetwork \
        -p 9200:9200 \
        -p 9300:9300 \
        -e "discovery.type=single-node" \
        elasticsearch:7.9.3"
    docker_exec $DOCKER_CMD
}

kibana () {
    DOCKER_CMD="docker network create somenetwork"
    docker_exec $DOCKER_CMD
    DOCKER_CMD="docker run -d \
        --name kibana \
        --net somenetwork \
        -p 5601:5601 \
        kibana:7.9.3"
    docker_exec $DOCKER_CMD
}

nextcloud () {
    DOCKER_CMD="docker run -d \
        --name=nextcloud \
        -p 8442:80 \
        -p 8443:443 \
        nextcloud"
    docker_exec $DOCKER_CMD
}

golang () {
    DOCKER_CMD="docker run -itd \
	--name golang \
	-p 9090:9090 \
        -v ${VOLUME}/www:/home/www \
        golang"
    docker_exec $DOCKER_CMD
}

mongo-express () {
    DOCKER_CMD="docker run -d \
        --name mongo-express \
        -p 8081:8081 \
        -e ME_CONFIG_BASICAUTH_USERNAME="mongo" \
        -e ME_CONFIG_BASICAUTH_PASSWORD="mongo-password" \
        -e ME_CONFIG_OPTIONS_EDITORTHEME="monokai" \
        -e ME_CONFIG_MONGODB_SERVER="127.0.0.1" \
        -e ME_CONFIG_MONGODB_PORT="27017" \
        mongo-express"
    docker_exec $DOCKER_CMD
}
